package com.cc.visitor.controller;

import com.cc.alltype.ResponseResult;
import com.cc.visitor.entity.UserWeixin;
import com.cc.visitor.service.UserWeixinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @author chanchaw
 * @create 2024-09-17 17:47
 */
@CrossOrigin
@RestController
@RequestMapping("/userWeixin")
public class UserWeixinController {
    @Autowired
    private UserWeixinService service;
    @PostMapping("/get8OpenId01/{openId}")
    public ResponseResult get8OpenId01(@PathVariable String openId){
        return ResponseResult.ok(service.select8OpenId(openId));
    }

    @PostMapping("/get8OpenId02")
    public ResponseResult get8OpenId02(@RequestBody String openId){
        return ResponseResult.ok(service.select8OpenId(openId));
    }
    @PostMapping("/get8Type")
    public ResponseResult get8Type(@RequestBody Integer type){
        return ResponseResult.ok(service.select8Type(type));
    }
    @PostMapping("/selectAll")
    public ResponseResult selectAll(){
        return ResponseResult.ok(service.selectAll());
    }
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody UserWeixin record){
        return ResponseResult.ok(service.insert(record));
    }
    @PostMapping("/insertMini")
    public ResponseResult insertMini(@RequestBody UserWeixin record){
        return ResponseResult.ok(service.insertMini(record));
    }

    /**
     * 小程序注册页面支持新增/修改两个功能
     * 1. 参数有主键则修改
     * 2. 没有主键
     *  2.1. 根据 unionId 查询到用户则修改
     *  2.2. 根据 unionId 没有用户则新增
     * @param record
     * @return
     */
    @PostMapping("/saveMini")
    public ResponseResult saveMini(@RequestBody UserWeixin record){
        return ResponseResult.ok(service.saveMini(record));
    }
    @PostMapping("/delete")
    public ResponseResult delete(@RequestBody Integer id){
        return ResponseResult.ok(service.delete(id));
    }
    @PostMapping("/update")
    public ResponseResult update(@RequestBody UserWeixin record){
        return ResponseResult.ok(service.update(record));
    }
    @PostMapping("/getUserType")
    public ResponseResult getUserType(@RequestBody Map<String, String> params){
        String openId = params.get("openId");
        return ResponseResult.ok(service.getUserType(openId));
    }
    @PostMapping("/get8RealName")
    public ResponseResult get8RealName(@RequestBody String name){
        return ResponseResult.ok(service.get8RealName(name));
    }

    /**
     * 获取所有访客数据，用于在管理后台中修改访客数据
     * @return
     */
    @PostMapping("/getAllVisitor")
    public ResponseResult getAllVisitor(){
        return ResponseResult.ok(service.getAllVisitor());
    }
}
